﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BL.BetterControls
{
    [ToolboxData("<{0}:_Textbox Description=\"\" LabelClass=\"\" runat=\"server\"></{0}:_Textbox>")]
    public class _Textbox : TextBox
    {
        public string LabelClass { get { return ViewState["LabelClass"] != null ? (string)ViewState["LabelClass"] : ""; } set { ViewState["LabelClass"] = value; } }
        public string Description { get { return ViewState["Description"] != null ? (string)ViewState["Description"] : ""; } set { ViewState["Description"] = value; } }
        public bool Valid { get { return ViewState["Valid"] != null ? (bool)ViewState["Valid"] : true; } set { ViewState["Valid"] = value; } }
        

        protected override void Render(HtmlTextWriter writer)
        {

            if (this.ToolTip == "")
                this.ToolTip = this.Description;

            string labelDisable = "";

            if (!this.Enabled)
                labelDisable = "disabled";

            if (Valid)
            {
                CssClass = CssClass.Replace(" error", "");
                LabelClass = LabelClass.Replace(" error", "");
            }
            else
            {
                CssClass += " error";
                LabelClass += " error";
            }

            

            if (LabelClass != String.Empty)
                writer.Write("<label id=\"" + this.ClientID + "_label\"  class=\"" + LabelClass + "\" " + labelDisable + " for=\"" + this.ClientID + "\" title=\"" + this.ToolTip + "\">" + this.Description + "</label>");
            else
                writer.Write("<label id=\"" + this.ClientID + "_label\" for=\"" + this.ClientID + "\" " + labelDisable + " title=\"" + this.ToolTip + "\">" + this.Description + "</label>");
            
            base.Render(writer);


            //if (ErrorMessage != "")
            //{
            //    writer.Write("<small class=\"error\">{0}</small>", ErrorMessage);
            //}
            

        }

    }
}
